import request from "@/utils/request";
import { OrderParams, OrderStatus, ResultOrder, SettleAccounts, SettleAccountsParams } from "@/type/OrderType";
import { ResponseType } from "@/type/ResponseType";

enum Enum {
   fetchOrderListAPI = "/order/list",
   fetchOrderStatusAPI = "/order/todoCounts",
   cancelOrderAPI = "/order/cancel",
   settleAccountsInfoAPI = "/checkout/order",
   fetchOrderDetailAPI = "/order/detail",
   submitOrderAPI = "/checkout/submit",
   paymentOrderAPI = "/order/pay"
}

/**
 * @description 获取订单列表的接口
 * */
export const fetchOrderListAPI = (params: OrderParams) => request.get<ResultOrder, ResponseType<ResultOrder>>(Enum.fetchOrderListAPI, { params });

/**
 * @description 获取订单状态的接口
 * */
export const fetchOrderStatusAPI = () => request.get<{ counts: OrderStatus }, ResponseType<{ counts: OrderStatus }>>(Enum.fetchOrderStatusAPI);

/**
 * @description 取消订单的接口
 * */
export const cancelOrderAPI = (orderId: number) => request.post<string[], ResponseType<string[]>>(Enum.cancelOrderAPI, { orderId });

/**
 * @description 获取订单结算信息的接口
 * */
export const settleAccountsInfoAPI = (params: SettleAccountsParams) => request.get<any, ResponseType<any>>(Enum.settleAccountsInfoAPI, { params });


/**
 * @description 提交订单的接口
 * */
export const submitOrderAPI = (data: SettleAccountsParams & { remark?: string, payType?: string }) => request.post<SettleAccounts, ResponseType<SettleAccounts>>(Enum.submitOrderAPI, data);

/**
 * @description 支付订单的接口
 * */
export const paymentOrderAPI = (params: { orderId: string, payType: string }) => request.get<string[], ResponseType<string[]>>(Enum.paymentOrderAPI, { params });

/**
 * @description 获取订单详情的接口
 * */
export const fetchOrderDetailAPI = (orderId: string) => request.get(Enum.fetchOrderDetailAPI, { params: { orderId } });

